﻿using System;
using System.Windows.Forms;
using Company.BLL;
using Company.Interface.GC;
using Company.Interface.KDT.SXXK;
using Company.Interface.KDT.GC;
using Company.Interface.SXXK;
using Janus.Windows.ExplorerBar;
using Company.BLL.KDT;
using Company.Interface.SXXK.BangKe;
using Company.Interface.Report.SXXK;
using DevExpress.LookAndFeel;
using Company.BLL.KDT.SXXK;

namespace Company.Interface
{
    public partial class MainForm : Form
    {
        #region SXXK
        private static QueueForm queueForm = new QueueForm();
        // Nguyên phụ liệu.
        private NguyenPhuLieuForm nplForm;

        private NguyenPhuLieuSendForm nplSendForm;
        //private NguyenPhuLieu_Receive_Form nplReceiveForm;
        private NguyenPhuLieuManageForm nplManageForm;
        private NguyenPhuLieuRegistedForm nplRegistedForm;
        // Sản phẩm.
        //private SanPhamForm spForm;
        private SanPhamSendForm spSendForm;
        //private SanPham_Receive_Form spReceiveForm;
        private SanPhamManageForm spManageForm;
        private SanPhamRegistedForm spRegistedForm;
        
        // Định mức.
        //private DinhMuc_Form dmForm;
        private DinhMucSendForm dmSendForm;
        private DinhMucManageForm dmManageForm;
        private DinhMucRegistedForm dmRegistedForm;
        // Tờ khai mậu dịch.
        private ToKhaiMauDichForm tkmdForm;
        private ToKhaiMauDichSendForm tkmdSendForm;
        private ToKhaiMauDichManageForm tkmdManageForm;
        //Hồ sơ thanh lý
        private TaoHoSoThanhLyForm taoHSTLForm;
        private CapNhatHoSoThanhLyForm capNhatHSTLForm;
        private ThucHienThanhLyForm thucHienThanhLyForm;
        private TheoDoiHoSoThanhLyForm theoDoiHSTLForm;
        private ToKhaiMauDichRegisterForm tkmdRegisterForm;
        #endregion

        //-----------------------------------------------------------------------------------------------
        
        #region GiaCong
        // Hợp đồng.
        private HopDongRegistedForm hdgcRegistedForm;
        private HopDongManageForm hdgcManageForm;
        private HopDongEditForm hdgcForm;

        //Định mức
        private DinhMucGCManageForm dmgcManageForm;
        private DinhMucGCSendForm dmgcSendForm;
        private DinhMucGCRegistedForm dmgcRegistedForm;
        //Phụ kiện
        private PhuKienGCSendForm pkgcSendForm;
        private PhuKienGCManageForm pkgcManageForm;
        private PhuKienGCRegistedForm pkgcRegistedForm;
        //tờ khai phiếu chuyển tiếp gia công
        private ToKhaiGCChuyenTiepNhapForm tkgcCTNhapForm;
        private ToKhaiGCCTSendForm tkgcctSendForm;
        private ToKhaiGCCTManagerForm theodoiTKGCCTForm;
        #endregion


        private void khoitao_GiaTriMacDinh()
        {
            GlobalSettings.KhoiTao_GiaTriMacDinh();
            statusBar.Panels["DoanhNghiep"].Text = statusBar.Panels["DoanhNghiep"].ToolTipText = string.Format("Doanh nghiệp: {0} - {1}", GlobalSettings.MA_DON_VI, GlobalSettings.TEN_DON_VI);
            statusBar.Panels["HaiQuan"].Text = statusBar.Panels["HaiQuan"].ToolTipText = string.Format("Đơn vị Hải quan: {0} - {1}", GlobalSettings.MA_HAI_QUAN, GlobalSettings.TEN_HAI_QUAN);
        }
        public static void ShowQueueForm()
        {
            queueForm.Show();
        }
        public static void AddToQueueForm(HangDoi hd)
        {
            queueForm.HDCollection.Add(hd);
            queueForm.RefreshQueue();
        }
        public MainForm()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        private void MainForm_Load(object sender, EventArgs e)
        {

            this.khoitao_GiaTriMacDinh();

            backgroundWorker1.RunWorkerAsync();                
            //MessageBox.Show("ok");
            //LoginForm f = new LoginForm();
            //f.ShowDialog(this);
            //if (!f.IsLogin)
            //{
            //    this.Close();
            //}
        }

        private void expSXXK_ItemClick(object sender, ItemEventArgs e)
        {
            switch (e.Item.Key)
            {
                // Khai báo NPL.
                case "nplKhaiBao":
                    this.show_NguyenPhuLieuSendForm();
                    break;
                // Theo dõi NPL.
                case "nplTheoDoi":
                    this.show_NguyenPhuLieuManageForm();
                    break;
                // NPL đã đăng ký.
                case "nplDaDangKy":
                    this.show_NguyenPhuLieuRegistedForm();
                    break;

                // Khai báo SP.
                case "spKhaiBao":
                    this.show_SanPhamSendForm();
                    break;

                // Theo dõi SP.
                case "spTheoDoi":
                    this.show_SanPhamManageForm();
                    break;

                // SP đã đăng ký.
                case "spDaDangKy":
                    this.show_SanPhamRegistedForm();
                    break;
                                    
                // Khai báo ĐM.
                case "dmKhaiBao":
                    this.show_DinhMucSendForm();
                    break;
                // Theo dõi ĐM.
                case "dmTheoDoi":
                    this.show_DinhMucManageForm();
                    break;
                // ĐM đã đăng ký
                case "dmDaDangKy":
                    this.show_DinhMucRegistedForm();
                    break;
                                        
                // Tờ khai mậu dịch.
                case "tkNhapKhau":
                    this.show_ToKhaiMauDichForm("NSX");
                    break;
                case "tkXuatKhau":
                    this.show_ToKhaiMauDichForm("XSX");
                    break;
                
                //Hồ sơ thanh lý
                case "AddHSTL":
                    this.show_TaoHoSoThanhLyForm();
                    break;
                case "UpdateHSTL":
                    this.show_CapNhatHoSoThanhLyForm();
                    break;               
                case "ManageHSTL":
                    this.show_TheoDoiHoSoThanhLyForm();
                    break;
                case "BCNPLXuatNhapTon":
                    this.ShowBCNPLXuatNhapTon();
                    break;
                case "BCThueXNK":
                    this.ShowBCThueXNK();
                    break;
                case "BKTKN":
                    this.ShowBKTKN();
                    break;
                case "BKTKX":
                    this.ShowBKTKX();
                    break;
            }
        }

        private void ShowBKTKX()
        {
        }

        private void ShowBKTKN()
        {
        }

        private void ShowBCThueXNK()
        {
            Company.Interface.Report.SXXK.BCThueXNK bc = new Company.Interface.Report.SXXK.BCThueXNK();
            bc.BindReport(GlobalSettings.MA_HAI_QUAN);
            bc.ShowPreview();
        }

        private void ShowBCNPLXuatNhapTon()
        {
            BCNPLXuatNhapTon bc = new BCNPLXuatNhapTon();
            bc.BindReport(GlobalSettings.MA_HAI_QUAN);
            bc.ShowPreview();
        }

        private void show_TaoHoSoThanhLyForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("TaoHoSoThanhLyForm") || forms[i].Name.ToString().Equals("BK02WizardForm") || forms[i].Name.ToString().Equals("BK01WizardForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            taoHSTLForm = new TaoHoSoThanhLyForm();
            taoHSTLForm.MdiParent = this;
            taoHSTLForm.Show();
        }
        private void show_CapNhatHoSoThanhLyForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("CapNhatHoSoThanhLyForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            capNhatHSTLForm = new CapNhatHoSoThanhLyForm();
            capNhatHSTLForm.MdiParent = this;
            capNhatHSTLForm.Show();
        }
        private void show_ThucHienThanhLyForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("ThucHienThanhLyForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            thucHienThanhLyForm = new ThucHienThanhLyForm();
            thucHienThanhLyForm.MdiParent = this;
            thucHienThanhLyForm.Show();
        }
        private void show_TheoDoiHoSoThanhLyForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("TheoDoiHoSoThanhLyForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            theoDoiHSTLForm = new TheoDoiHoSoThanhLyForm();
            theoDoiHSTLForm.MdiParent = this;
            theoDoiHSTLForm.Show();
        }
        //private void uiButton1_Click(object sender, EventArgs e)
        //{
        //    new NguyenPhuLieu_Form().ShowDialog();
        //}

        //private void uiButton2_Click(object sender, EventArgs e)
        //{
        //    new SanPham_Form().ShowDialog();
        //}

        //private void explorerBar1_ItemClick(object sender, ItemEventArgs e)
        //{
        //    this.Cursor = Cursors.WaitCursor;
        //    switch (e.Item.Key)
        //    {
        //            // Nguyên phụ liệu.
        //        case "nplNhap":
        //            this.show_NguyenPhuLieu_Form();
        //            break;
        //        case "nplSend":
        //            this.show_NguyenPhuLieu_Send_Form();
        //            break;
        //        case "nplManage":
        //            this.show_NguyenPhuLieu_Manage_Form();
        //            break;

        //            // Sản phẩm.
        //        case "spNhap":
        //            this.show_SanPham_Form();
        //            break;
        //        case "spSend":
        //            this.show_SanPham_Send_Form();
        //            break;
        //        case "spManage":
        //            this.show_SanPham_Manage_Form();
        //            break;

        //            // Định mức.
        //        case "dmNhap":
        //            this.show_DinhMuc_Form();
        //            break;
        //        case "dmSend":
        //            this.show_DinhMuc_Send_Form();
        //            break;
        //        case "dmManage":
        //            this.show_DinhMuc_Manage_Form();
        //            break;

        //            // Tờ khai mậu dịch.
        //        case "tkNhapKhau_SXXK":
        //            this.show_ToKhaiNhapKhauSXXK_Form();
        //            break;

        //        case "tkSend_SXXK":
        //            this.show_ToKhaiMauDich_Send_Form();
        //            break;

        //        case "tkManage_SXXK":
        //            this.show_ToKhaiMauDich_Manage_Form();					
        //            break;

        //    }
        //    this.Cursor = Cursors.Default;
        //}

        private void show_NguyenPhuLieuForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("NguyenPhuLieuForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            nplForm = new NguyenPhuLieuForm();
            nplForm.MdiParent = this;
            nplForm.Show();
        }

        //-----------------------------------------------------------------------------------------
        private void show_NguyenPhuLieuSendForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("NguyenPhuLieuSendForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            nplSendForm = new NguyenPhuLieuSendForm();
            nplSendForm.MdiParent = this;
            nplSendForm.Show();
        }

        //-----------------------------------------------------------------------------------------------
        private void show_NguyenPhuLieuManageForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("NguyenPhuLieuManageForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            nplManageForm = new NguyenPhuLieuManageForm();
            nplManageForm.MdiParent = this;
            nplManageForm.Show();
        }
        //-----------------------------------------------------------------------------------------------
        private void show_NguyenPhuLieuRegistedForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("NguyenPhuLieuRegistedForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            nplRegistedForm = new NguyenPhuLieuRegistedForm();
            nplRegistedForm.MdiParent = this;
            nplRegistedForm.Show();
        }
        
        ////-----------------------------------------------------------------------------------------------
        private void show_SanPhamManageForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("SanPhamManageForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            spManageForm = new SanPhamManageForm();
            spManageForm.MdiParent = this;
            spManageForm.Show();

        }

        //-----------------------------------------------------------------------------------------------
        private void show_SanPhamRegistedForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("SanPhamRegistedForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            spRegistedForm = new SanPhamRegistedForm();
            spRegistedForm.MdiParent = this;
            spRegistedForm.Show();
        }

        ////-----------------------------------------------------------------------------------------
        private void show_SanPhamSendForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("SanPhamSendForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            spSendForm = new SanPhamSendForm();
            spSendForm.MdiParent = this;
            spSendForm.Show();

        }

        ////-----------------------------------------------------------------------------------------

        //private void show_DinhMuc_Form()
        //{
        //    Form[] forms = this.MdiChildren;
        //    for (int i = 0; i < forms.Length; i++)
        //    {
        //        if (forms[i].Name.ToString().Equals("DinhMuc_Form"))
        //        {
        //            forms[i].Activate();
        //            return;
        //        }
        //    }
        //    dmForm = new DinhMuc_Form();
        //    dmForm.MdiParent = this;
        //    dmForm.Show();
        //}

        //-----------------------------------------------------------------------------------------
        private void show_DinhMucSendForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("DinhMucSendForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            dmSendForm = new DinhMucSendForm();
            dmSendForm.MdiParent = this;
            dmSendForm.Show();
        }

        //-----------------------------------------------------------------------------------------------
        private void show_DinhMucManageForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("DinhMucManageForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            dmManageForm = new DinhMucManageForm();
            dmManageForm.MdiParent = this;
            dmManageForm.Show();

        }
        private void show_DinhMucRegistedForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("DinhMucRegistedForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            dmRegistedForm = new DinhMucRegistedForm();
            dmRegistedForm.MdiParent = this;
            dmRegistedForm.Show();

        }

        //-----------------------------------------------------------------------------------------
        private void show_ToKhaiMauDichForm(string nhomLoaiHinh)
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals(nhomLoaiHinh))
                {
                    forms[i].Activate();
                    return;
                }
            }
            tkmdForm = new ToKhaiMauDichForm();
            tkmdForm.OpenType = OpenFormType.Insert;
            tkmdForm.Name = nhomLoaiHinh;
            tkmdForm.NhomLoaiHinh = nhomLoaiHinh;
            tkmdForm.MdiParent = this;
            tkmdForm.Show();
        }

        //-----------------------------------------------------------------------------------------
        private void show_ToKhaiMauDichSendForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("ToKhaiMauDichSendForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            tkmdSendForm = new ToKhaiMauDichSendForm();
            tkmdSendForm.MdiParent = this;
            tkmdSendForm.Show();
        }
        
        //-----------------------------------------------------------------------------------------
        
        private void show_ToKhaiMauDichManageForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("ToKhaiMauDichManageForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            tkmdManageForm = new ToKhaiMauDichManageForm();
            tkmdManageForm.MdiParent = this;
            tkmdManageForm.Show();
        }

        private void expKhaiBao_TheoDoi_ItemClick(object sender, ItemEventArgs e)
        {
            switch (e.Item.Key)
            {
                case "tkSend":
                    this.show_ToKhaiMauDichSendForm();
                    break;
                case "tkManage":
                    this.show_ToKhaiMauDichManageForm();
                    break;
                case "tkDaDangKy":
                    this.show_ToKhaiMauDichRegisterForm();
                    break;
            }
        }

        private void expKD_ItemClick(object sender, ItemEventArgs e)
        {
            switch (e.Item.Key)
            {
                case "tkNhapKhau_KD":
                    this.show_ToKhaiMauDichForm("NKD");
                    break;
                case "tkXuatKhau_KD":
                    this.show_ToKhaiMauDichForm("XKD");
                    break;
            }
        }

        private void expDT_ItemClick(object sender, ItemEventArgs e)
        {
            switch (e.Item.Key)
            {
                case "tkNhapKhau_DT":
                    this.show_ToKhaiMauDichForm("NDT");
                    break;
                case "tkXuatKhau_DT":
                    this.show_ToKhaiMauDichForm("XDT");
                    break;
            }
        }

        private void expGiaCong_ItemClick(object sender, ItemEventArgs e)
        {
            switch (e.Item.Key)
            {
                case "hdgcNhap":
                    this.show_HopDongForm();
                    break;
                case "hdgcRegisted":
                    this.show_HopDongRegistedForm();
                    break;
                case "hdgcManage":
                    this.show_HopDongManageForm();
                    break;
                case "dmSend":
                    this.show_DinhMucGCSendForm();
                    break;
                case "dmManage":
                    this.show_DinhMucGCManageForm();
                    break;
                case "dmRegisted":
                    this.show_DinhMucGCRegistedForm();
                    break;
                case "pkgcNhap":
                    this.show_PhuKienGCSendForm();
                    break;
                case "pkgcManage":
                    this.show_PhuKienGCManageForm();
                    break;
                case "pkgcRegisted":
                    this.show_PhuKienGCRegistedForm();
                    break;
                case "tkNhapKhau_GC":
                    this.show_ToKhaiMauDichForm("NGC");
                    break;
                case "tkXuatKhau_GC":
                    this.show_ToKhaiMauDichForm("XGC");
                    break;
                case "tkGCCTNhap" :
                    this.show_ToKhaiGCChuyenTiepNhap("N");
                    break;
                case "tkGCCTXuat":
                    this.show_ToKhaiGCChuyenTiepNhap("X");
                    break;
                case "theodoiTKCT":
                    this.show_ToKhaiGCCTManagerForm();
                    break;
                case "khaibaoTKCT":
                    this.show_ToKhaiGCCTSendForm();
                    break;
            }
        }
        private void show_ToKhaiMauDichRegisterForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("ToKhaiMauDichRegisterForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            tkmdRegisterForm = new ToKhaiMauDichRegisterForm();
            tkmdRegisterForm.MdiParent = this;
            tkmdRegisterForm.Show();
        }
        
        //-----------------------------------------------------------------------------------------
        private void show_ToKhaiGCCTManagerForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("ToKhaiGCCTManagerForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            theodoiTKGCCTForm = new ToKhaiGCCTManagerForm();
            theodoiTKGCCTForm.MdiParent = this;
            theodoiTKGCCTForm.Show();
        }

        //-----------------------------------------------------------------------------------------
        private void show_ToKhaiGCCTSendForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("ToKhaiGCCTSendForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            tkgcctSendForm = new ToKhaiGCCTSendForm();
            tkgcctSendForm.MdiParent = this;
            tkgcctSendForm.Show();
        }

        //-----------------------------------------------------------------------------------------
        private void show_HopDongRegistedForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("HopDongRegistedForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            hdgcRegistedForm = new HopDongRegistedForm();
            hdgcRegistedForm.MdiParent = this;
            hdgcRegistedForm.Show();
        }
        private void show_HopDongManageForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("HopDongManageForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            hdgcManageForm = new HopDongManageForm();
            hdgcManageForm.MdiParent = this;
            hdgcManageForm.Show();
        }
        private void show_HopDongForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("HopDongEditForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            hdgcForm = new HopDongEditForm();            
            hdgcForm.MdiParent = this;
            hdgcForm.Show();
        }
        private void show_DinhMucGCSendForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("DinhMucGCSendForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            dmgcSendForm = new DinhMucGCSendForm();
            dmgcSendForm.MdiParent = this;
            dmgcSendForm.Show();
        }
        private void show_ToKhaiGCChuyenTiepNhap(string nhomLoaiHinh)
        {
            Form[] forms = this.MdiChildren;

            for (int i = 0; i < forms.Length; i++)
                {
                    if (forms[i].Name.ToString().Equals(nhomLoaiHinh))
                    {
                        forms[i].Activate();
                        return;
                    }
                }
            tkgcCTNhapForm = new ToKhaiGCChuyenTiepNhapForm();
            tkgcCTNhapForm.NhomLoaiHinh = nhomLoaiHinh;
            tkgcCTNhapForm.Name = nhomLoaiHinh;
            tkgcCTNhapForm.OpenType = OpenFormType.Insert;
            tkgcCTNhapForm.MdiParent = this;
            tkgcCTNhapForm.Show();
        }
        //private void show_ToKhaiGCChuyenTiepXuat()
        //{
        //    Form[] forms = this.MdiChildren;
        //    for (int i = 0; i < forms.Length; i++)
        //    {
        //        if (forms[i].Name.ToString().Equals("ToKhaiGCChuyenTiepXuatForm"))
        //        {
        //            forms[i].Activate();
        //            return;
        //        }
        //    }
        //    tkgcCTXuatForm = new ToKhaiGIaCongChuyenTiepXuatForm();
        //    tkgcCTXuatForm.MdiParent = this;
        //    tkgcCTXuatForm.Show();
        //}
        private void show_DinhMucGCManageForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("DinhMucGCManageForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            dmgcManageForm = new DinhMucGCManageForm();
            dmgcManageForm.MdiParent = this;
            dmgcManageForm.Show();
        }
        private void show_DinhMucGCRegistedForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("DinhMucGCRegistedForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            dmgcRegistedForm = new DinhMucGCRegistedForm();
            dmgcRegistedForm.MdiParent = this;
            dmgcRegistedForm.Show();
        }
        private void show_PhuKienGCSendForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("PhuKienGCSendForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            pkgcSendForm = new PhuKienGCSendForm();
            pkgcSendForm.MdiParent = this;
            pkgcSendForm.Show();
        }
        private void show_PhuKienGCManageForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("PhuKienGCManageForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            pkgcManageForm = new PhuKienGCManageForm();
            pkgcManageForm.MdiParent = this;
            pkgcManageForm.Show();
        }
        private void show_PhuKienGCRegistedForm()
        {
            Form[] forms = this.MdiChildren;
            for (int i = 0; i < forms.Length; i++)
            {
                if (forms[i].Name.ToString().Equals("PhuKienGCRegistedForm"))
                {
                    forms[i].Activate();
                    return;
                }
            }
            pkgcRegistedForm = new PhuKienGCRegistedForm();
            pkgcRegistedForm.MdiParent = this;
            pkgcRegistedForm.Show();
        }

        private void pnlMain_SelectedPanelChanged(object sender, Janus.Windows.UI.Dock.PanelActionEventArgs e)
        {

        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            queueForm.Dispose();
        }

        private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            Company.BLL.SXXK.ToKhai.ToKhaiMauDich tokhai = new Company.BLL.SXXK.ToKhai.ToKhaiMauDich();
            NhanNhoForm f = new NhanNhoForm();
            uint hannhacnho = Convert.ToUInt32(System.Configuration.ConfigurationManager.AppSettings["HanThanhKhoan"]);
            uint thoigianTK = Convert.ToUInt32(System.Configuration.ConfigurationManager.AppSettings["ThongBaoThanhKhoan"]);
            System.Data.DataSet ds = tokhai.GetThongBao(hannhacnho, thoigianTK);
            if (ds == null || ds.Tables[0].Rows.Count == 0)
            {             
            }
            else
            {
                queueForm.notifyIcon1.ShowBalloonTip(5000, "Thông báo ", "Có "+ds.Tables[0].Rows.Count+" tờ khai sắp hết hạn chưa được thanh khoản.\nVào phần nhắc nhở để xem chi tiết.", ToolTipIcon.Warning);
                //f.Show();                   
            }
        }

        private void cmMain_CommandClick(object sender, Janus.Windows.UI.CommandBars.CommandEventArgs e)
        {
            switch (e.Command.Key)
            {
                case "NhacNho":
                    {
                        Company.BLL.SXXK.ToKhai.ToKhaiMauDich tokhai = new Company.BLL.SXXK.ToKhai.ToKhaiMauDich();
                        NhanNhoForm f = new NhanNhoForm();
                        uint hannhacnho = Convert.ToUInt32(System.Configuration.ConfigurationManager.AppSettings["HanThanhKhoan"]);
                        uint thoigianTK = Convert.ToUInt32(System.Configuration.ConfigurationManager.AppSettings["ThongBaoThanhKhoan"]);
                        System.Data.DataSet ds = tokhai.GetThongBao(hannhacnho, thoigianTK);
                        f.ds = ds;
                        if (f.ds == null || f.ds.Tables[0].Rows.Count == 0)
                        {
                            BaseForm baseForm = new BaseForm();
                            baseForm.ShowMessage("Không có nhắc nhở nào cả", false);
                            return;
                        }
                        else
                        {                            
                            f.ShowDialog(); 
                        }
                    }
                    break;
                case "cmdThoat":
                    {
                        this.Close();
                    }
                    break;
            }
        }
        ////-----------------------------------------------------------------------------------------
        //private void cmMain_CommandClick(object sender, CommandEventArgs e)
        //{
        //    switch (e.Command.Key)
        //    {
        //        case "cmdReceiveAll":
        //            this.show_NguyenPhuLieu_Receive_Form();
        //            this.show_SanPham_Receive_Form();
        //            break;
        //        case "cmdGhi":
        //            MessageBox.Show("Ghi thành công!");
        //            break;
        //    }
        //}

        //private void expGiaCong_ItemClick(object sender, Janus.Windows.ExplorerBar.ItemEventArgs e)
        //{
        //    this.Cursor = Cursors.WaitCursor;
        //    switch (e.Item.Key)
        //    {
        //        // Hợp đồng.
        //        case "hdgcNhap":
        //            this.show_HopDong_Form();
        //            break;
        //    }
        //    this.Cursor = Cursors.Default;			
        //}

        //private void explorerBar1_ItemClick_1(object sender, Janus.Windows.ExplorerBar.ItemEventArgs e)
        //{
        //    ASEANKhaiBao01Form f = new ASEANKhaiBao01Form();
        //    f.MdiParent = this;
        //    f.Show();
        //}
    }
}